package com.diy.sigmund.diycommon.entity.enumerate;

import com.diy.sigmund.diycommon.util.VerifyParamUtil;
import java.util.function.BiFunction;

/**
 * 参数校验策略枚举
 *
 * @author ylm-sigmund
 * @since 2021/5/24 21:51
 */
public enum VerifyParamPolicyEnum {

    /** 必须不为null */
    NOT_NULL(VerifyParamUtil::isNotNull, "%s必须不为null", 1),
    /** 字符串必须非空 */
    NOT_EMPTY(VerifyParamUtil::isNotEmpty, "%s字符串必须非空", 1),
    /** 字符串必须非空，trim()后的长度必须大于0 */
    NOT_BLANK(VerifyParamUtil::isNotBlank, "%s字符串必须非空，trim()后的长度必须大于0", 1),
    /** 字符串格式不匹配 */
    MATCHES(VerifyParamUtil::isNotMatches, "%s字符串格式不匹配", 1),
    /** 必须为true */
    ASSERT_TRUE(VerifyParamUtil::assertTrue, "%s必须为true", 1),
    /** 必须为false */
    ASSERT_FALSE(VerifyParamUtil::assertFalse, "%s必须为false", 1),
    /** 必须大于等于 */
    MIN(VerifyParamUtil::min, "%s必须大于等于%s", 2),
    /** 必须小于等于 */
    MAX(VerifyParamUtil::max, "%s必须小于等于%s", 2),
    /** 数字必须在%s和%s之间 */
    BETWEEN_INTEGER(VerifyParamUtil::betweenInteger, "%s数字必须在%s和%s之间", 3),
    /** 时间必须小于 */
    PAST(VerifyParamUtil::past, "%s时间必须小于%s", 2),
    /** 时间必须大于 */
    FUTURE(VerifyParamUtil::future, "%s时间必须大于%s", 2),
    /** 时间必须在%s和%s之间 */
    BETWEEN_DATE(VerifyParamUtil::betweenDate, "%s时间必须在%s和%s之间", 3),
    ;
    /**
     * 参数校验策略
     */
    private BiFunction<Object, Object, Boolean> VerifyParamPolicy;
    /**
     * 提示信息
     */
    private String msg;
    /**
     * 需要替换的数量
     */
    private int replacementQuantity;

    VerifyParamPolicyEnum(
            BiFunction<Object, Object, Boolean> verifyParamPolicy, String msg, int replacementQuantity) {
        VerifyParamPolicy = verifyParamPolicy;
        this.msg = msg;
        this.replacementQuantity = replacementQuantity;
    }

    public BiFunction<Object, Object, Boolean> getVerifyParamPolicy() {
        return VerifyParamPolicy;
    }

    public String getMsg() {
        return msg;
    }

    public int getReplacementQuantity() {
        return replacementQuantity;
    }
}
